package org.example.service;


import com.github.pagehelper.PageHelper;
import org.example.dto.ShanjiaZhxg;
import org.example.dto.Shanjiaimagexg;
import org.example.entity.Shanjia;
import org.example.entity.Shanpin;
import org.example.mapper.*;
import org.example.result.Pages;
import org.example.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ShanjiaService {
    @Autowired
    Shanjiamapper shanjiamapper;
    @Autowired
    Dianpumapper dianpumapper;
    @Autowired
    private ShanpinService shanpinService;
    @Autowired
    private Shanpinfelemapper shanpinfelemapper;

    @Autowired
    private DingdanService dingdanService;
    @Autowired
    private Dingdanmapper dingdanmapper;
    @Autowired
    private Kaidianmapper kaidianmapper;


    /**
     * 商家登录
     * @param shanjia
     */
    public Shanjia login(Shanjia shanjia) {
        return shanjiamapper.chaxun(shanjia);
    }

    /**
     * 商家注册
     * @param shanjia
     */
    public void sizhuche(Shanjia shanjia) {
        shanjia.setUpdateTime(LocalDateTime.now());
        shanjia.setCreateTime(LocalDateTime.now());
        shanjia.setYingye(1);
        shanjia.setImage("http://localhost:8080/image/2.jpg");
        dianpumapper.dianpuxz("商家未设置","商家未设置","http://localhost:8080/image/2.jpg","http://localhost:8080/image/2.jpg",shanjia.getUsername());
        shanjiamapper.inst(shanjia);
    }

    /**
     * 忘记密码
     * @param shanjia
     */
    public void wangji(Shanjia shanjia) {
        shanjiamapper.wangji(shanjia);
    }

    /**
     * 查询
     * @param username
     * @return
     */
    public Shanjia chaxun(String username) {
        Shanjia shanjia=new Shanjia();
        shanjia.setUsername(username);
        return shanjiamapper.chaxun(shanjia);
    }

    /**
     * 修改店铺状态
     * @param username
     */
    public void xg(String username) {
        Shanjia shanjia=chaxun(username);
        shanjiamapper.xg(shanjia);
    }

    /**
     * 账号修改
     * @param shanjiaZhxg
     */
    public void zhxg(ShanjiaZhxg shanjiaZhxg) {
        shanjiamapper.zhxg(shanjiaZhxg);
    }

    /**
     * 修改image
     *
     *
     */
    public void xgimage(Shanjiaimagexg shanjiaimagexg) {
        shanjiaimagexg.setNewname("http://localhost:8080/image/"+shanjiaimagexg.getNewname());
        shanjiamapper.xgimage(shanjiaimagexg);
    }


    /**
     * 注销
     * @param username
     */
    public void delete(String username) {


        shanpinService.xgplsc("","","",username);
        shanpinfelemapper.deletes(username);
        dianpumapper.zx(username);
        dianpumapper.zxgz(username);
        dingdanmapper.xgzx(username);
        dingdanmapper.clsc(1);
        shanjiamapper.delete(username);
        kaidianmapper.sczh(username);
        kaidianmapper.scz(username);
    }
}
